import pandas as pd
# Import the wrapper objects for model interaction.
from examples.example_10_advanced_ciw.ex_10_ciw_model import N
from vidigi.ciw import event_log_from_ciw_recs
from vidigi.animation import animate_activity_log
import plotly.io as pio
pio.renderers.default = "notebook"
import os
import ciw
View Imported Code for the ciw model
import ciw
# From https://ciw.readthedocs.io/en/latest/Tutorial/tutorial_ii.html
N = ciw.create_network(
arrival_distributions=[ciw.dists.Exponential(rate=0.3),
ciw.dists.Exponential(rate=0.2),
None],
service_distributions=[ciw.dists.Exponential(rate=2.0),
ciw.dists.Exponential(rate=1.4),
ciw.dists.Exponential(rate=0.85)],
routing=[[0.0, 0.3, 0.7],
[0.0, 0.0, 1.0],
[0.0, 0.0, 0.0]],
number_of_servers=[1, 2, 2]
)ciw.seed(42)
Q = ciw.Simulation(N)
RESULTS_COLLECTION_PERIOD = 180
Q.simulate_until_max_time(RESULTS_COLLECTION_PERIOD)
recs = Q.get_all_records()event_log_test = event_log_from_ciw_recs(
recs,
node_name_list=["cold_food", "hot_food", "till"]
)
event_log_test| entity_id | pathway | event_type | event | time | resource_id | |
|---|---|---|---|---|---|---|
| 0 | 1 | Model | arrival_departure | arrival | 0.126644 | NaN |
| 1 | 1 | Model | queue | hot_food_wait_begins | 0.126644 | NaN |
| 2 | 1 | Model | resource_use | hot_food_begins | 0.126644 | 1.0 |
| 3 | 1 | Model | resource_use | hot_food_ends | 0.356376 | 1.0 |
| 4 | 1 | Model | queue | till_wait_begins | 0.356376 | NaN |
| ... | ... | ... | ... | ... | ... | ... |
| 707 | 83 | Model | arrival_departure | arrival | 178.350594 | NaN |
| 708 | 83 | Model | queue | hot_food_wait_begins | 178.350594 | NaN |
| 709 | 83 | Model | resource_use | hot_food_begins | 178.350594 | 1.0 |
| 710 | 83 | Model | resource_use | hot_food_ends | 179.016262 | 1.0 |
| 711 | 83 | Model | arrival_departure | depart | 179.016262 | NaN |
712 rows × 6 columns
# Create a suitable class to pass in the resource numbers to the animation function
class model_params():
def __init__(self):
self.cold_food_servers = 1
self.hot_food_servers = 2
self.tills = 2
params = model_params()# Create required event_position_df for vidigi animation
event_position_df = pd.DataFrame([
{'event': 'arrival',
'x': 30, 'y': 550,
'label': "Arrival"},
{'event': 'cold_food_wait_begins',
'x': 200, 'y': 510,
'label': "Waiting for Cold Food"},
{'event': 'cold_food_begins',
'x': 210, 'y': 370,
'resource':'cold_food_servers',
'label': "Being Served Cold Food"},
{'event': 'hot_food_wait_begins',
'x': 505, 'y': 510,
'label': "Waiting for Hot Food"},
{'event': 'hot_food_begins',
'x': 505, 'y': 370,
'resource':'hot_food_servers',
'label': "Being Served Hot Food"},
{'event': 'till_wait_begins',
'x': 350, 'y': 170,
'label': "Waiting for Till"},
{'event': 'till_begins',
'x': 350, 'y': 120,
'resource':'tills',
'label': "Being Served at Till"},
{'event': 'exit',
'x': 600, 'y': 10,
'label': "Exit"}
])
event_position_df| event | x | y | label | resource | |
|---|---|---|---|---|---|
| 0 | arrival | 30 | 550 | Arrival | NaN |
| 1 | cold_food_wait_begins | 200 | 510 | Waiting for Cold Food | NaN |
| 2 | cold_food_begins | 210 | 370 | Being Served Cold Food | cold_food_servers |
| 3 | hot_food_wait_begins | 505 | 510 | Waiting for Hot Food | NaN |
| 4 | hot_food_begins | 505 | 370 | Being Served Hot Food | hot_food_servers |
| 5 | till_wait_begins | 350 | 170 | Waiting for Till | NaN |
| 6 | till_begins | 350 | 120 | Being Served at Till | tills |
| 7 | exit | 600 | 10 | Exit | NaN |
# Create animation
params = model_params()
animate_activity_log(
event_log=event_log_test,
event_position_df=event_position_df,
scenario=model_params(),
simulation_time_unit="minutes",
debug_mode=True,
setup_mode=False,
every_x_time_units=1,
include_play_button=True,
entity_icon_size=20,
gap_between_entities=15,
gap_between_queue_rows=25,
gap_between_resources=30,
plotly_height=700,
frame_duration=400,
frame_transition_duration=600,
plotly_width=1200,
override_x_max=700,
override_y_max=600,
limit_duration=RESULTS_COLLECTION_PERIOD,
wrap_queues_at=25,
wrap_resources_at=50,
step_snapshot_max=75,
time_display_units="minutes",
start_time="12:00",
text_size=20,
display_stage_labels=False,
add_background_image="cafe_floorplan.drawio (1).png"
)Animation function called at 17:10:49
Iteration through time-unit-by-time-unit logs complete 17:10:49
Snapshot df concatenation complete at 17:10:49
Reshaped animation dataframe finished construction at 17:10:50
Placement dataframe finished construction at 17:10:50
Output animation generation complete at 17:10:50
Total Time Elapsed: 1.79 seconds